<%@ page import="java.io.PrintWriter" %>
<%@ page import="cn.tedu.web.lsw.JdbcUtils" %><%--
  Created by IntelliJ IDEA.
  User: 21688
  Date: 2021/12/13
  Time: 8:52
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    String username = request.getParameter("u");
    String password=request.getParameter("p");
    String code=request.getParameter("c");
    //System.out.println(username);
    //System.out.println(password);
    //System.out.println(code);
    //HttpSession session=request.getSession();
    Object c=session.getAttribute("c");
    boolean isTrue = code !=null && code.equals(c);
    if(!isTrue){
        //PrintWriter writer=response.getWriter();
        //writer.write("error");
        //writer.flush();
        //writer.close();
        //return;
        out.print("验证码错误");
    }else {
        String sql = "SELECT id FROM `user` WHERE username = ? AND password=MD5(?)";
        Long id = JdbcUtils.select(sql, Long.class, username, password);
        String message = id != null && id>0L? "登录成功!" : "登录失败!";
        //response.setContentType("text/html;charset=utf-8");
        // TODO
        // 在此处通过 JDBC 来检查前端传递的 username 和 password 在数据库中是否存在
        // 如果存在，在页面显示登录成功，否则显示登录失败

        //PrintWriter writer = response.getWriter();
        //System.out.println("message");
        //writer.write(message);
        //writer.flush();
        //writer.close();
        out.print(message);
    }



%>

